package com.qzsf.backend.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qzsf.backend.common.Result;
import com.qzsf.backend.dto.ParticipationCreateDTO;
import com.qzsf.backend.mapper.ParticipationMapper;
import com.qzsf.backend.service.ParticipationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*
 * @Author: Dennis Chen
 * @CreateTime: 2024/11/25 15:26 周一
 * @Email 1429278462@qq.com
 * @Remark 用户活动参与情况服务层实现类
 * @Version 1.0
 */
@Service
public class ParticipationServiceImpl implements ParticipationService {
    @Autowired
    private ParticipationMapper participationMapper;

    @Override
    public Result getParticipationByCondition(String userName, String eventName, int pageNo, int pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        return Result.success(new PageInfo<>(participationMapper.getParticipation(userName, eventName)));
    }

    @Override
    public Result getUsersWithIncompleteParticipation(int eventId) {
        return Result.success(participationMapper.getUsersWithIncompleteParticipation(eventId));
    }

    @Override
    public Result addParticipation(List<ParticipationCreateDTO> participationList) {
        if (participationList != null && !participationList.isEmpty()) {
            participationMapper.batchInsertParticipation(participationList);
            return Result.success();
        }else{
            return Result.error("传入数据异常");
        }
    }

    @Override
    public Result addUnParticipation(List<ParticipationCreateDTO> participationList) {
        if (participationList != null && !participationList.isEmpty()) {
            participationMapper.batchInsertUnParticipation(participationList);
            return Result.success();
        }else{
            return Result.error("传入数据异常");
        }
    }

    @Override
    public Result deleteParticipationById(int id) {
        if(participationMapper.deleteParticipationById(id)>0){
            return Result.success();
        }else{
            return Result.error("删除失败");
        }
    }
}
